<template>
  <div ref="echart" class="hello" :style="size">

  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  name: 'HelloWorld',
  props: {
    options: Object,
    size: Object
  },
  data() {
    return {
      myChart: {}
    }
  },
  mounted () {
    console.log(this.options);
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(this.$refs.echart);   // 解决重复调用多个echarts的问题
    // 绘制图表
    let options = this.options

    this.myChart.setOption(options)

    // myChart.setOption({
    //   title: {
    //     text: 'ECharts 入门示例'
    //   },
    //   tooltip: {},
    //   xAxis: {
    //     data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    //   },
    //   yAxis: {},
    //   series: [{
    //     name: '销量',
    //     type: 'bar',
    //     data: [5, 20, 36, 10, 10, 20]
    //   }]
    // });
  },
  watch: {
    options(newValue, oldValue) {
      this.myChart.setOption(newValue)
    }
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
